// ---------------------------------------------------------------------
//
// -- 单机小游戏基类包
// -- author £
//
// ---------------------------------------------------------------------
const CommonUtil = require('CommonUtil'),
    CommonInfo = require('CommonInfo'),
    AppInfo = require('AppInfo'),
    Platform = require('Platform'),
    GameConfig = require('GameConfig'),
    superClass = require('wgbase').BaseWGMediator,
    modelSuper = require('wgbase').BaseWGModel;

let singlebase = {
    //中介层基类
    BaseSingleMediator: cc.Class({
        name: "BaseSingleMediator",
        extends: superClass,
        properties: {

        },

        initCtor: function () {
            CommonUtil.mysuper(superClass, this, 'initCtor');
            this._rankShow = false;
        },

        clearData: function () {
            CommonUtil.mysuper(superClass, this, 'clearData');
        },

        register: function (v) {
            CommonUtil.mysuper(superClass, this, 'register', v);
        },

        onRelease: function () {
            CommonUtil.mysuper(superClass, this, 'onRelease');
        },

        onShow: function () {
            CommonUtil.mysuper(superClass, this, 'onShow');

            if (AppInfo.wx) {
                GameConfig.userProto.bindM(this);
            }
        },

        onHide: function () {
            CommonUtil.mysuper(superClass, this, 'onHide');
        },

        /** 开始切换至游戏界面 */
        toGameScene: function () {
            CommonUtil.mysuper(superClass, this, 'toGameScene');

            Platform.postMessage({
                message: 'hide',
            });
        },

        /** 开始切换至大厅界面 */
        toLobbyScene: function () {
            CommonUtil.mysuper(superClass, this, 'toLobbyScene');
        },

        // -------------------------------------------------------------

        getWorldRank: function (xhrData) {
            require('MainMediator').main_getWorldRank(xhrData);
        },

        // -----------------------------------------------------------------------

        friendRankHandler: function (data) {
            let d = {};

            this._rankShow = true;
            Platform.scaleSharedCanvas();
            Platform.postMessage({ message: 'hide' });
            d.message = 'friend';
            d.userid = require('CommonInfo').userID();
            Platform.postMessage(d);
            require('MainMediator').main_friendRankHandler(data);
        },

        groupRankHandler: function (data) {
            let d = {};

            this._rankShow = true;
            require('Platform').scaleSharedCanvas();
            Platform.postMessage({ message: 'hide' });
            d.message = 'group';
            d.userid = require('CommonInfo').userID();
            d.shareTicket = data;
            Platform.postMessage(d);
            require('MainMediator').main_groupRankHandler(data);
        },

        hideRankHandler: function () {
            this._rankShow = false;
            require('MainMediator').main_hideRankHandler();
        },

        worldRankHandler: function () {
            if (!CommonInfo.checkRegisted((this.getWorldRankHandler).bind(this)))
                return;

            this.getWorldRankHandler();
        },

        getWorldRankHandler: function () {
            this._rankShow = true;
            require('MainMediator').main_worldRankHandler();
            GameConfig.userProto.queryWorldRank(
                (this.getWorldRank).bind(this)
            );
            Platform.hideBannerAd();
        },
    }),

    //模型层基类
    BaseSingleModel: cc.Class({
        name: "BaseSingleModel",
        extends: modelSuper,
        properties: {

        },
    }),

};

module.exports = singlebase;